﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace baroIstatistik.Class
{
	public class user
	{
        private int userID;
        public int UserID { get { return userID; }  }


        private string username;
        public string Username { get { return username; } set { username = value; } }
        
        private string pass;
        public string Pass { get { return pass; } set { pass = value; } }
     
               
        private string name;
        public string Name { get { return name; } set { name = value; } }
       
        private string surname;
        public string Surname { get { return surname; } set { surname = value; } }
 
        
        
        private string regdate;
        public string Regdate { get { return regdate; } set { regdate = value; } }


        public  user(string kullanici,string password,string isim,string soyisim,string kayittarihi)
        {
            username = kullanici;
            pass = password;
            name = isim;
            surname = soyisim;
            regdate = kayittarihi;
    
        }

        public  user(int ID)
        {
            userID = ID;
        
        }

        public user()
        {

        }

        public void getir()
        {
            SqlConnection sqlcon = connection.baglanti;

            SqlCommand sqlcmd = new SqlCommand("select * from userTable where userID=@userID",sqlcon);
            sqlcmd.Parameters.AddWithValue("@userID", userID);

            sqlcon.Open();

            SqlDataReader sdr = sqlcmd.ExecuteReader();
            while (sdr.Read())
            {
                username = sdr["username"].ToString();
                name = sdr["name"].ToString();
                surname = sdr["surname"].ToString();
                pass = sdr["password"].ToString();
                
            }


            sqlcon.Close();
        
        }
        public void guncelle()
        {
            string[] kolonlar = { "username", "password", "name", "surname" };
            string[] degerler = { username, pass,name, surname };


            dataCUD.guncelle("userTable", kolonlar, degerler, "userID", userID.ToString());
        }


        public void ekle()
        {
            string[] degerler = {username,pass,name,surname,regdate };

            string[] kolonlar = { "username", "password", "name", "surname", "regDate" };

            dataCUD.ekle("userTable", kolonlar, degerler);
        }

        public void sil()
        {

            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("delete from userTable where userID=@userID",sqlcon);
            sqlcmd.Parameters.AddWithValue("@userID",userID);

            sqlcon.Open();

            sqlcmd.ExecuteNonQuery();

            sqlcon.Close();

        
        }

        public  List<user> tumunugetir()
        {
         List<user> us = new List<user>();

            SqlConnection sqlcon= connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("select * from userTable",sqlcon);
            sqlcon.Open();
            SqlDataReader sdr= sqlcmd.ExecuteReader();

            while (sdr.Read())
	{
        user u = new user();
        u.userID = Convert.ToInt32(sdr["userID"]);
        u.username = sdr["username"].ToString();
        u.name = sdr["name"].ToString();
        u.surname = sdr["surname"].ToString();

        us.Add(u);
	}

            sqlcon.Close();

            return us;
        }

    
    
    }
}